package com.ccpdown.adapter;

import java.util.ArrayList;
import java.util.List;

import com.ccpdown.layout.ItemContextView;
import com.ccpdown.util.show.BitmapDownloader;
import com.ccpdown.view.R;
import com.ccpdown.vo.ConfiedText;
import com.ccpdown.vo.Software;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class IconfiedTextListAdapter extends BaseAdapter {

	private Activity context;
	private List<ConfiedText> item;
	private LayoutInflater inflater;

	public IconfiedTextListAdapter(Activity context, List<ConfiedText> objects) {
		this.context = context;
		this.item = objects;
		inflater = LayoutInflater.from(context);
	}

	public void setItem(List list) {
		this.item = list;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LinearLayout ly = (LinearLayout) inflater.inflate(R.layout.typeitem,
				null);
		// 获得各种控件;
		ImageView ivTypeIcon = (ImageView) ly.findViewById(R.id.ivTypeIcon);
		TextView tvTypeName = (TextView) ly.findViewById(R.id.tvTypeName);
		TextView tvCountN = (TextView) ly.findViewById(R.id.tvCountN);
		ImageView ivTypeButton = (ImageView) ly.findViewById(R.id.ivTypeButton);

		// 给控件赋值;
		BitmapDownloader.setSocketImg(ivTypeIcon, item.get(position).typeIcon,
				context.getResources().getDrawable(R.drawable.defaulticon));
		tvTypeName.setText(item.get(position).typeName);
		tvCountN.setText(String.valueOf((item.get(position).typeCount)));
		return ly;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.item.size();
	}

	@Override
	public ConfiedText getItem(int position) {
		// TODO Auto-generated method stub
		return item.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

}
